package com.hospital.auth.module.controller;

import com.hospital.auth.module.service.TUserService;
import com.hospital.common.base.Result;
import com.hospital.common.dto.auth.module.UserDto;
import com.hospital.common.validator.auth.module.ValidateGroup;
import com.hospital.common.vo.auth.module.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户登录注册接口
 * @author yhn
 * @version 1.0
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private TUserService userService;

    /**
     * 用户注册
     * @param userDto 注册表单
     * @return 注册结果
     */
    @PostMapping("/register")
    public Result<?> register(@Validated(ValidateGroup.UserGroup.Register.class) @RequestBody UserDto userDto){
        userService.register(userDto);
        return Result.success();
    }
    /**
     * 用户登录
     * @param userDto 登录表单
     * @return 登录结果
     */
    @PostMapping("/login")
    public Result<UserVo> login(@Validated(ValidateGroup.UserGroup.Login.class) @RequestBody UserDto userDto){
        return Result.success(userService.login(userDto));
    }
    /**
     * 用户登出
     * @return 登出结果
     * @param account 账号
     */
    @GetMapping("/logout")
    public Result<?> logout(@RequestParam("account") String account){
        userService.logout(account);
        return Result.success();
    }

}
